from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager

def create_app():
    app = Flask(__name__)
    CORS(app)
    
    # 配置JWT
    app.config['JWT_SECRET_KEY'] = 'your-secret-key'  # 在生产环境中应使用环境变量
    jwt = JWTManager(app)
    
    # 注册路由蓝图
    from .routes import auth_bp, home_bp, product_bp, cart_bp, order_bp
    app.register_blueprint(auth_bp, url_prefix='/api/auth')
    app.register_blueprint(home_bp, url_prefix='/api')
    app.register_blueprint(product_bp, url_prefix='/api')
    app.register_blueprint(cart_bp, url_prefix='/api')
    app.register_blueprint(order_bp, url_prefix='/api')
    
    return app